''''''

"""
1.定义一个长方形类，有长和宽两个属性，再分别定义计算 周长  和 面积的方法
2.定义一个正方形类，继承长方形类；同时也有计算周长和面积的方法
"""


class Rectangle:
    def __init__(self, length, width):
        self.length = length
        self.width = width

    def calculate_perimeter(self):
        return 2 * (self.length + self.width)

    def calculate_area(self):
        return self.length * self.width


my_rectangle = Rectangle(length=3, width=5)

# 周长和面积
perimeter = my_rectangle.calculate_perimeter()
print(f"长方形周长是{perimeter}")
area = my_rectangle.calculate_area()
print(f"长方形面积是{area}")


class Square(Rectangle):
    def __init__(self, side_length=4):
        super().__init__(length=side_length, width=side_length)


my_square = Square(side_length=4)
perimeter = my_square.calculate_perimeter()

print(f"正方形周长是{perimeter}")
area = my_square.calculate_area()
print(f"正方形面积是{area}")
